set printback=OFF.  
  
TITLE LIS Cross-section Data center in Luxembourg.  
  
TITLE email: usersupport@lisdatacenter.org .  
  
TITLE LIS Self Teaching Package 2022.  
  
TITLE Part I: Inequality, poverty, and social policy.  
TITLE SPSS version.  
  
TITLE last change of this version of the syntax: 15-01-2022.  
  
TITLE Exercise 6: Comparing income concepts.  
  
   
define gt06data ()   
get file = gt06h / keep = did dhi hi33 hpublic hifactor hpub_i hpub_u hpub_a hiprivate hxitsc hpopwgt nhhmem grossnet hwgt.   
!enddefine   
define us04data ()   
get file = us04h / keep = did dhi hi33 hpublic hifactor hpub_i hpub_u hpub_a hiprivate hxitsc hpopwgt nhhmem grossnet hwgt.   
!enddefine   
define dk04data ()   
get file = dk04h / keep = did dhi hi33 hpublic hifactor hpub_i hpub_u hpub_a hiprivate hxitsc hpopwgt nhhmem grossnet hwgt.   
!enddefine   
define hu05data ()   
get file = hu05h / keep = did dhi hi33 hpublic hifactor hpub_i hpub_u hpub_a hiprivate hxitsc hpopwgt nhhmem grossnet hwgt.   
!enddefine   
define il05data ()   
get file = il05h / keep = did dhi hi33 hpublic hifactor hpub_i hpub_u hpub_a hiprivate hxitsc hpopwgt nhhmem grossnet hwgt.   
!enddefine   
   
   
define dataprepare ().    
SET ERRORS OFF.        
compute miss_comp = 0.     
if (missing(dhi) or missing(hifactor) or missing(hi33) or missing(hpub_i) or missing(hpub_u) or missing(hpub_a) or missing(hiprivate) or missing(hxitsc)) miss_comp = 1.     
select if miss_comp eq 0.     
* create person weight as hwgt times number of household members.      
compute wt = hwgt*nhhmem .      
compute mi_tb = hifactor + hi33 + hiprivate.     
compute siti_tb = hifactor +hi33 +  hiprivate + hpub_i + hpub_u - hxitsc.     
compute sa_tb = hifactor + hi33 + hiprivate + hpub_a.     
!enddefine .      
  
     
define prepare ().       
SET ERRORS OFF.      
* select only records if dhi filled.      
select if not missing(inc_var) .      
* recode negaive dhi into zero     
if (inc_var <0) inc_var =0.     
EXECUTE.      
compute inc_var_log = ln(inc_var).      
EXECUTE.      
if (missing(inc_var_log) & NOT(missing(inc_var))) inc_var_log =0.      
EXECUTE.      
weight by wt.      
!enddefine .      
     
define decilecalc ().      
*** decile procedure.       
preserve .       
set tvars names tnumbers values.       
dataset declare decileratio.       
WEIGHT BY hwgt.      
sort cases by did.       
split file by did.       
OMS           
 / select tables           
 / if command = ['Frequencies'] subtypes=['Statistics']           
 /destination format = sav        outfile = 'decileratio'           
 /columns sequence = [l1 r2] .       
frequencies variables = inc_var_log     
  /percentiles = 25 50 75      
  /format = notable .      
OMSEND.      
weights off.      
restore.      
match files file = *      
  /table = 'decileratio'      
  /rename (var1 = did)      
  /by did .     
DATASET CLOSE decileratio.     
!enddefine .       
      
define topbottom ().      
weight by wt.      
COMPUTE iqr= inc_var_log_75- inc_var_log_25.      
EXECUTE.      
* detect upper bound for extreme values      
COMPUTE upper_bound= inc_var_log_75+ (iqr * 3).      
EXECUTE.      
COMPUTE lower_bound= inc_var_log_25- (iqr * 3).      
EXECUTE.      
* top code income at upper bound for extreme values      
if inc_var >exp(upper_bound) inc_var =exp(upper_bound).       
EXECUTE.      
* bottom code income at lower bound for extreme values      
if inc_var <exp(lower_bound) inc_var =exp(lower_bound).      
EXECUTE.      
* create equivalised income, set equivalence scale as square root of household members      
compute ey = inc_var /(nhhmem**0.5).       
!enddefine .       
  
define run ().  
prepare.  
decilecalc.  
topbottom.  
!enddefine.   
  
define povcalc ().    
aggregate outfile = *     
   mode = addvariables     
   / break = did     
   / ey_median = median(ey)  .      
compute povline5 = ey_median * 0.5 .    
match files file=*/keep    
did povline5.    
Dataset copy poverty.    
!enddefine .     
  
define povcalccnt ().    
MATCH FILES /FILE=*     
  /FILE='poverty'     
  /RENAME (did = d0)     
  /DROP= d0.     
EXECUTE.    
compute poor50 = 0 .    
if ey lt povline5 poor50 = 100 .    
variable labels poor50 'overall poverty rate 50%'.    
weight by wt.  
descriptives  poor50 /statistics=mean /format=notable.   
!enddefine .    
    
define ginicalc ()      
sort cases by ey (a).       
compute cumwgt = cumwgt + wt.       
leave cumwgt.       
aggregate outfile= *      
   mode = addvariables      
    /break= did      
    /meany= mean(ey)      
    /meanr= mean (cumwgt)      
    /n=n.      
compute devy= ey - meany.       
compute rank= cumwgt/n.       
compute devr = (rank - 0.5).       
compute prod= devy*devr.       
aggregate outfile= *      
    /break=did      
    /sumprod= sum(prod)      
    /meany= mean(ey)      
    /n=n.      
compute cov= sumprod/(n-1).      
compute gini=cov*2/meany.      
formats gini (f10.4).      
descriptives var=gini .    
!enddefine .    
    
define edhi ()  
dataprepare.   
compute inc_var = dhi.   
run.      
povcalc.    
compute poor50 = 0 .    
if ey lt povline5 poor50 = 100 .    
variable labels poor50 'overall poverty rate 50%'.    
weight by wt.  
descriptives  poor50 /statistics=mean /format=notable.    
TITLE Gini using dhi.    
ginicalc.      
!enddefine.  
    
    
define emi ()    
dataprepare.  
compute inc_var = mi_tb.     
run.   
TITLE Poverty using mi_tb.       
povcalccnt.  
TITLE Gini using mi_tb.  
ginicalc.   
!enddefine.    
   
  
define esiti ()  
dataprepare.  
compute inc_var = siti_tb.   
run.  
TITLE Gini using siti_tb.    
povcalccnt.  
TITLE Gini using siti_tb.    
ginicalc.    
!enddefine.    
   
  
define esa ()   
dataprepare.   
compute inc_var = sa_tb.  
run.  
TITLE Poverty using sa_tb.   
povcalccnt.      
TITLE Gini using sa_tb.  
ginicalc.   
!enddefine.    
   
define stat ()  
frequencies variables = grossnet.    
descriptives variables = hpublic hpub_i hpub_u hpub_a /statistics=mean /format=notable.  
!enddefine   
  
TITLE ==================================================.  
TITLE Guatemala.   
TITLE ==================================================.  
gt06data.  
edhi.    
gt06data.     
emi.   
gt06data.     
esiti.  
gt06data.     
esa.  
gt06data.    
stat.  
  
TITLE ==================================================.  
TITLE United States.  
TITLE ==================================================.   
us04data.  
edhi.    
us04data.     
emi.   
us04data.     
esiti.  
us04data.     
esa.  
us04data.    
stat.  
  
TITLE ==================================================.  
TITLE Denmark.  
TITLE ==================================================.  
dk04data.  
edhi.    
dk04data.     
emi.   
dk04data.     
esiti.  
dk04data.     
esa.  
dk04data.    
stat.  
  
TITLE ==================================================.  
TITLE Hungary.  
TITLE ==================================================.   
hu05data.  
edhi.    
hu05data.     
emi.   
hu05data.     
esiti.  
hu05data.     
esa.  
hu05data.    
stat.   
  
TITLE ==================================================.  
TITLE Israel.  
TITLE ==================================================.    
il05data.  
edhi.    
il05data.     
emi.   
il05data.     
esiti.  
il05data.     
esa.  
il05data.    
stat.